/*
 * Copyright (C) 2018 The Asiainfo-Ability Authors
 *
 *      Licensed under the Apache License, Version 2.0 (the "License");
 *      you may not use this file except in compliance with the License.
 *      You may obtain a copy of the License at
 *
 *          http://www.apache.org/licenses/LICENSE-2.0
 *
 *      Unless required by applicable law or agreed to in writing, software
 *      distributed under the License is distributed on an "AS IS" BASIS,
 *      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *      See the License for the specific language governing permissions and
 *      limitations under the License.
 */

package org.asiainfo.ability.base.utils;


import org.asiainfo.ability.base.code.BizCode;
import org.asiainfo.ability.base.code.SystemCode;

/**
 * @Author: visen
 * @Date: 2018/1/16
 * @Description:
 *
 */
public class Response {
    private String code;
    private String desc;

    public Response(String code, String desc) {
        this.code = code;
        this.desc = desc;
    }
    private static final String EMPTY = "";
    public static String error(SystemCode systemCode) {
        return new StringBuilder("{\"code\":\"")
                .append(systemCode.getValue())
                .append("\",\"desc\":\"")
                .append(systemCode).append("\"}").toString();
    }
    public static String error(SystemCode systemCode, Object option) {

        return new StringBuilder("{\"code\":\"")
                .append(systemCode.getValue())
                .append("\",\"desc\":\"")
                .append(systemCode).append(" ").append(option).append("\"}").toString();
    }
    public static String error(String code, String desc) {

        return new StringBuilder("{\"code\":\"")
                .append(code)
                .append("\",\"desc\":\"")
                .append(desc).append("\"}").toString();
    }
    public static String error(int code, String desc) {

        return new StringBuilder("{\"code\":\"")
                .append(code)
                .append("\",\"desc\":\"")
                .append(desc).append("\"}").toString();
    }
    public static String error(BizCode code) {

        return new StringBuilder("{\"code\":\"")
                .append(code.getValue())
                .append("\",\"desc\":\"")
                .append(code).append("\"}").toString();
    }
    public static String success() {
        return success(EMPTY);
    }
    public static String success(String value) {
        return new StringBuilder("{\"code\":\"")
                .append("1")
                .append("\",\"desc\":\"")
                .append(value).append("\"}").toString();
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }

    public String toJson(){
        return JsonUtils.toJSON(this);
    }
}
